﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace BLL
{
    public class Helper_District
    {
        /// <summary>
        /// 获取的地址展示形式
        /// </summary>
        public enum ShowType
        {
            逗号连接,
            斜线连接,
            无符号连接
        }
        /// <summary>
        /// 根据地区ID（districtId）获取该地区的全路径表现形式
        /// </summary>
        /// <param name="districtId"></param>
        /// <param name="showType"></param>
        /// <returns></returns>
        public string Get_FullPath_DistrictId(int districtId, ShowType showType)
        {
            //获取地区信息
            DataRow drDistrict = DAL.Common.Query_Row("select Name,CityID from T_District where Id = " + districtId);
            string district = drDistrict["Name"].ToString();
            //获取城市信息
            DataRow drCity = DAL.Common.Query_Row("select Name,ProID from T_City where Id = " + drDistrict["CityID"].ToString());
            string city = drCity["Name"].ToString();
            //获取省信息
            DataRow drProvince = DAL.Common.Query_Row("select Name from T_Province where Id = " + drCity["ProID"].ToString());
            string province = drProvince["Name"].ToString();
            List<string> strList = new List<string>();
            if (province != city)
            {
                strList.Add(province);
            }
            strList.Add(city);
            strList.Add(district);
            return Get_StrByShowType(strList, showType);
        }

        private string Get_StrByShowType(List<string> strList, ShowType showType)
        {
            string result = string.Empty;
            foreach (string str in strList)
            {
                switch (showType)
                {
                    case ShowType.逗号连接:
                        result += str + "，";
                        break;
                    case ShowType.斜线连接:
                        result += str + "/";
                        break;
                    case ShowType.无符号连接:
                        result += str;
                        break;
                }
            }
            if (showType != ShowType.无符号连接 && result.Length > 1)
            {
                result = Common.StringDispose.Left(result, -1);
            }
            return result;
        }
    }
}
